package cn.sciento.farm.devicemanager.gateway.model.downlink.fertilizer.inject;

import cn.sciento.farm.devicemanager.common.constant.MqttConstant;
import cn.sciento.farm.devicemanager.gateway.model.downlink.AbstractBlockData;
import cn.sciento.farm.devicemanager.gateway.model.downlink.MqttContent;
import cn.sciento.farm.devicemanager.gateway.model.uplink.fertilizer.inject.InjectFertilizerControlParam;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.HashMap;
import java.util.Map;

import static cn.sciento.farm.devicemanager.common.constant.MqttConstant.INJECT_FERTILIZER_CONTROL_BLOCK_ID;

@Data
@EqualsAndHashCode(callSuper = false)
public class InjectFertilizerControlPacket extends AbstractBlockData {
    private String eui;
    private Boolean activate;
    private Integer mode;
    private InjectFertilizerControlParam param;

    @Override
    public String generateId() {
        return String.format(INJECT_FERTILIZER_CONTROL_BLOCK_ID,eui );
    }

    @Override
    public String generateStatus() {
        return activate.toString();
    }

    @Override
    public MqttContent generate() {
        String topic = String.format(MqttConstant.INJECT_FERTILIZER_CONTROL_TOPIC, this.eui);
        Map map = new HashMap<String,Object>();
        map.put("activate",activate);
        map.put("param",param);
        map.put("mode",mode);
        String payload = JSON.toJSONString(map);
        return new MqttContent(topic,payload);
    }
}
